/*
 * p11729.cpp
 *
 *  Created on: 2013-4-19
 *      Author: zy
 */

#include<cstdio>
#include<algorithm>
using namespace std;
struct node
{
	int j, b;
	bool friend operator<(node a, node b)
	{
		return a.j > b.j;
	}
} a[1005];
int main()
{
	int n;
	int cas = 0;
	while (scanf("%d", &n) && n)
	{
		cas++;
		for (int i = 1; i <= n; i++)
			scanf("%d%d", &a[i].b, &a[i].j);
		sort(a+1,a+n+1);
		int ans = 0, cur = 0;
		for (int i = 1; i <= n; i++)
		{
			cur += a[i].b;
			ans = max(ans, cur + a[i].j);
		}
		printf("Case %d: %d\n", cas, ans);
	}
	return 0;

}
